package com.hualan.sfzy.service.course.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.entity.Announcement;
import com.hualan.sfzy.mapper.course.AnnouncementMapper;
import com.hualan.sfzy.service.course.AnnouncementService;
import com.hualan.sfzy.vo.AnnouncementVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AnnouncementServiceImpl implements AnnouncementService {
    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public int add(Announcement entity) {

        return announcementMapper.insert(entity);
    }

    @Override
    public int edit(Announcement entity) {
        return announcementMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return announcementMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return announcementMapper.deleteBatch(ids);
    }

    @Override
    public List<Announcement> find() {
        return announcementMapper.selectAll();
    }

    @Override
    public List<AnnouncementVo> findVo() {
        return announcementMapper.selectVo();
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Announcement entity) {
        PageHelper.startPage(pageNum,pageSize);
       List<Announcement> list = announcementMapper.select(entity);
        PageInfo<Announcement> pageInfo = new PageInfo<>(list);
        Map<String, Object> result = new HashMap<>();
        result.put("list", pageInfo.getList());
        result.put("total", pageInfo.getTotal());
        result.put("pageNum", pageInfo.getPageNum());
        result.put("pageSize", pageInfo.getPageSize());
        result.put("pages", pageInfo.getPages());

        return result;
    }

    @Override
    public Announcement findById(Integer id) {
        return announcementMapper.selectById(id);
    }
}
